<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/10/4
 * Time: 13:16
 */

namespace App\Plugin\HostServer\Models;


class PnHostSvUserMoneyLog extends HostServerBase
{
    public static function getType($field=''){
        $type=[
            1=>'充值',
            2=>'新购服务器',
            3=>'续费',
            4=>'提现',
            5=>'退款',
            6=>'注册域名',
            7=>'续费域名'
        ];
        return $field==''?$type:$type[$field];
    }
    /**
     * 取得会员
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(PnHostSvUser::class, 'user_id', 'id');
    }

    /**
     * 取得type 名字
     * @return array|mixed
     */
    public function getTypeNameAttribute()
    {
        return static::getType($this->type);
    }

    public static function add($data){
        if(in_array($data['type'],[1])){
            $data['money']=$data['money'];
        }else
        {
            $data['money']=-$data['money'];
        }
       return self::create($data);
    }

}